var Login = function () {

    var handleLogin = function() {
        $('.login-form').validate({
            errorElement: 'label', //default input error message container
            errorClass: 'help-inline', // default input error message class
            focusInvalid: false, // do not focus the last invalid input
            rules: {
                userid: {
                    required: true
                },
                passwd: {
                    required: true
                }
            },

            messages: {
                userid: {
                    required: "Chưa nhập Mã Số."
                },
                passwd: {
                    required: "Chưa nhập Mật Khẩu."
                }
            },

            invalidHandler: function (event, validator) { //display error alert on form submit   
                $('.alert-error', $('.login-form')).show();
            },

            highlight: function (element) { // hightlight error inputs
                $(element)
                .closest('.control-group').addClass('error'); // set error class to the control group
            },

            success: function (label) {
                $('.alert-error', $('.login-form')).hide();
                label.closest('.control-group').removeClass('error');
                label.remove();
            },

            errorPlacement: function (error, element) {
                error.addClass('help-small no-left-padding').insertAfter(element.closest('.input-icon'));
            },

            submitHandler: function (form) {
                form.submit();
            }
        });

        $('.login-form input').keypress(function (e) {
            if (e.which == 13) {
                if ($('.login-form').validate().form()) {
                    $('.login-form').submit();
                }
                return false;
            }
        });
    }

    return {
        //main function to initiate the module
        init: function () {
        	
            handleLogin();

            $.backstretch([
                "assets/img/bg/1.jpg",
                "assets/img/bg/2.jpg",
                "assets/img/bg/3.jpg",
                "assets/img/bg/4.jpg"
                ], {
                    fade: 1000,
                    duration: 8000
                });
	       
        }

    };

}();